package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.feign.cart.CartFeginClient;
import com.atguigu.gmall.model.cart.vo.AddCartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class CartController {

    @Autowired
    CartFeginClient cartFeginClient;

    /**
     * addCart.html?skuId=50&skuNum=1&sourceType=query
     * 添加到购物车
     * @param skuId
     * @param skuNum
     * @param model
     * @return
     */
    @GetMapping("/addCart.html")
    public String addCart(Long skuId, Integer skuNum, Model model) {
        //远程调用
        AddCartVO addCartVO = cartFeginClient.addToCart(skuId, skuNum).getData();


        model.addAttribute("skuInfo",addCartVO.getSkuInfo());
        model.addAttribute("skuNum",addCartVO.getSkuNum());
        return "cart/addCart";
    }

    @GetMapping("/cart.html")
    public String cartList() {
        return "cart/index";
    }

    @GetMapping("/cart/deleteChecked")
    public String deleteChecked() {
        cartFeginClient.deleteChecked();
        return "redirect:http://cart.gmall.com/cart.html";
    }

}
